package org.trinity.netdisk.enums;

import com.fasterxml.jackson.annotation.JsonValue;
import org.trinity.netdisk.exception.shareFile.InvalidShareDayException;

public enum ShareDays {
    /**
     * 链接永不过期
     */
    PERMANENT(-1, "永久"),
    /**
     * 一天后过期
     */
    OneDay(1, "一天"),
    /**
     * 一周后过期
     */
    OneWeek(7, "一周"),
    /**
     * 一个月后过期
     */
    OneMonth(30, "一个月");
    private Integer code;
    private String msg;

    ShareDays(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    @JsonValue
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static ShareDays integerToShareDays(int num) {
        switch (num) {
            case -1:
                return PERMANENT;
            case 1:
                return OneDay;
            case 7:
                return OneWeek;
            case 30:
                return OneMonth;
            default:
                throw new InvalidShareDayException();
        }
    }
}
